package com.dingwei.lesyndrome.adapter;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dingwei.lesyndrome.R;
import com.dingwei.lesyndrome.app.MyApplication;
import com.dingwei.lesyndrome.bean.MainBean;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.lihao.baselibrary.base.BaseActivity;
import com.lihao.baselibrary.utils.DisplayUtil;
import com.lihao.baselibrary.utils.MathUtil;
import com.lihao.baselibrary.utils.ScreenUtils;
import com.lihao.baselibrary.weight.MyRadioGroup;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created time 2018/2/24.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class PeripheryAdapter extends RecyclerArrayAdapter<MainBean.DataBean.PeripheryListBean> {
    public PeripheryAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new PeripheryHolder(parent);
    }

    public class PeripheryHolder extends BaseViewHolder<MainBean.DataBean.PeripheryListBean> {


        @Bind(R.id.img)
        ImageView mImg;
        @Bind(R.id.tv_selected)
        TextView mTvSelected;
        @Bind(R.id.tv_name)
        TextView mTvName;
        @Bind(R.id.tv_look)
        TextView mTvLook;
        @Bind(R.id.tv_distance)
        TextView mTvDistance;
        @Bind(R.id.layout)
        LinearLayout mLayout;

        public PeripheryHolder(ViewGroup parent) {
            super(parent, R.layout.item_periphery_type);
            ButterKnife.bind(this, itemView);

            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams((ScreenUtils.getScreenWidth(BaseActivity.context) - DisplayUtil.dip2px(BaseActivity.context, 60)) / 2, (ScreenUtils.getScreenWidth(BaseActivity.context) - DisplayUtil.dip2px(BaseActivity.context, 60)) / 2 / 5 * 3);
            mImg.setLayoutParams(lp);
            LinearLayout.LayoutParams lp1 = new LinearLayout.LayoutParams((ScreenUtils.getScreenWidth(BaseActivity.context) - DisplayUtil.dip2px(BaseActivity.context, 60)) / 2, ViewGroup.LayoutParams.WRAP_CONTENT);
            mLayout.setLayoutParams(lp1);

        }

        @Override
        public void setData(MainBean.DataBean.PeripheryListBean data) {
            super.setData(data);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            if (getDataPosition() == (getAllData().size() - 1)) {
                lp.setMargins(DisplayUtil.dip2px(BaseActivity.context, 16), 0, DisplayUtil.dip2px(BaseActivity.context, 16), 0);
                mLayout.setLayoutParams(lp);
            } else {
                lp.setMargins(DisplayUtil.dip2px(BaseActivity.context, 16), 0, 0, 0);
                mLayout.setLayoutParams(lp);
            }

            Glide.with(BaseActivity.context)
                    .load(data.img)
                    .apply(MyApplication.options)
                    .into(mImg);
            mTvSelected.setText(data.cname);
            mTvName.setText(data.title);
            mTvLook.setText(data.views+"");
            if (data.distance>1000){
                mTvDistance.setText(MathUtil.getTwoNum(data.distance/1000)+"km");
            }else {
                mTvDistance.setText(MathUtil.getTwoNum(data.distance)+"m");
            }

        }
    }
}
